package org.jtb.flickrportlet;

import org.jtb.quickr.PhotosResponse;
import org.jtb.quickr.PhotosResponse.Photo;
import java.util.List;

public class PhotosBean {
    private PhotosResponse photosResponse = null;
    
    public void setPhotosResponse(PhotosResponse photosResponse) {
        this.photosResponse = photosResponse;
    }
    
    public boolean isLoaded() {
        return photosResponse != null;
    }

    public void setLoaded(boolean loaded) {
        if (!loaded) {
            photosResponse = null;
        }
    }
    
    public int getPage() {
        return photosResponse.getPage();
    }
    
    public List<Photo> getPhotos() {
        if (photosResponse == null) {
            throw new IllegalStateException("photos response is not set");
        }
        return photosResponse.getPhotos();
    }  
    
    public int getPerPage() {
        return photosResponse.getPerPage();        
    }
    
    public int getPages() {
        return photosResponse.getPages();
    }
    
    public int getTotal() {
        return photosResponse.getTotal();
    }
    
    public boolean isMorePages() {
        return photosResponse.getPage() < photosResponse.getPages();
    }
            
    public int getFirstPhotoNumber() {
        int page = getPage();
        int perPage = getPerPage();
        int first = ((page-1)*perPage) + 1;

        return first;
    }

    public int getLastPhotoNumber() {
        int page = getPage();
        int perPage = getPerPage();
        int last = Math.min(page*perPage, getTotal());
        
        return last;
    }    
}
